package com.equipment;

import com.util.EncodingUtil;

/**
 * 国标一次发行
 * @author Administrator
 *
 */
public class IPORequest {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "C0"; // 扩展代码


	private String UpdateMKey = "01";//是否替换主控密钥，0为替换，1不替换 0
	private String ContractProvider2 = "";//提供商编码后4字节
	private String ContractType = "";//协约类型
	private String ContractVersion = "16";//合同版本  16
	private String ContractSerialNumber = "";//合同序列号 8

	private String bcc = "";// 异或校验


	/**
	 * 拼接数据帧
	 * @return
	 */
	public String getIPORequest(String updateMKey,String contractProvider2,String contractType,String contractVersion,String contractSerialNumber) {
		this.UpdateMKey = EncodingUtil.addzero(updateMKey, 1);
		this.ContractProvider2 = EncodingUtil.addzero(contractProvider2, 4);
		this.ContractType = EncodingUtil.addzero(contractType, 1);
		this.ContractVersion = EncodingUtil.addzero(ContractVersion, 1);
		this.ContractSerialNumber = EncodingUtil.addzero(contractSerialNumber, 8);
		Length = EncodingUtil.desToHex((broadening+UpdateMKey+ContractProvider2+ContractType+ContractVersion+ContractSerialNumber).length()/2,4);
		String DATA = RSCTL + Length + code + broadening + UpdateMKey+ContractProvider2+ContractType+ContractVersion+ContractSerialNumber;
		bcc = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		return  STX + DATA + bcc;
	}
}
